package com.chenlehao.controller;

import com.chenlehao.mapper.userMapper;
import com.chenlehao.pojo.pageBean;
import com.chenlehao.pojo.result;
import com.chenlehao.pojo.user;
import com.chenlehao.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
public class userController {
    @Autowired
    private userMapper userMapper;
    @Autowired
    private userService userService;

    @RequestMapping("/getAll")
    public result getAll() {
        List<user> userList = userMapper.list();
        System.out.println("请求通过" + userList);
        return result.success(userList);
    }

    @GetMapping("/pageList")
    public result getPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pageSize) {
        pageBean list = userService.pageList(page, pageSize);
        return result.success(list);
    }

    @PostMapping("/upload")
    public result upload(MultipartFile file) throws IOException {
        String url = userService.uploadOSS(file);
        return result.success(url);
    }

    @PostMapping("/login")
    public result login(String username) throws IOException {
        String str = userService.login(username);
        return result.success(str);
    }
}
